<?php
namespace Versal\AdminBundle\Dao;
use Versal\AdminBundle\Entity\Region;
use Doctrine\ORM\Query\ResultSetMapping;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of CommonDao
 *
 * @author Jorge
 */
class CommonDao{
     //put your code here
    protected $conexion;
    
    public function __construct($conexion){
        $this->conexion = $conexion;
    }
	
    public function getConexion(){
        return $this->conexion;
    }
    
    public function getRegiones(){
        $rsm = new ResultSetMapping;
        $rsm->addEntityResult('Versal\AdminBundle\Entity\Region', 'r');
        $rsm->addFieldResult('r', 'region_id', 'regionId'); // ($alias, $columnName, $fieldName)
        $rsm->addFieldResult('r', 'region_nombre', 'nombre');
        $rsm->addFieldResult('r', 'region_ordinal', 'regionOrdinal');
        $sql = 'call getRegiones(@errIdn, @errGls);';
        $query = $this->conexion->createNativeQuery($sql, $rsm);
        //$query->setParameter(1, 'romanb');
        $regiones = $query->getResult();                        
        return $regiones;
    }
       
}
